package cn.ven.dao;

import cn.ven.entity.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
public class ContentDaoImpl implements ContentDao {


    @Autowired
    MongoTemplate mongoTemplate;


    @Override
    public String addContent(Content content) {
         mongoTemplate.insert(content);
         return content.getId();
    }

    @Override
    public Content findById(String id) {

        return mongoTemplate.findById(id,Content.class);
    }

    @Override
    public void delContent(String id) {
        Query query =new Query(Criteria.where("id").is(id));
        mongoTemplate.remove(query,Content.class);
    }


}
